if __name__ == "__main__":
    import optparse
    import common_options
    import getpass
    import presetfile
    import common
    import presets
    import sys
    
    parser = optparse.OptionParser()
    common_options.add_options(parser)
    parser.add_option("-c", "--create", help="create preset file", action="store_true", dest="create", default=False)
    options, args = parser.parse_args()

    password = getpass.getpass("Master password: ")
    preset_file = presetfile.PresetFile(options.preset_file)
    if options.create:
        preset_file.save({}, password)
        sys.exit()
    else:
        if options.preset_name is None:
            sys.exit("Preset name not given!")

        user_data = dict([arg.split("=", 1) for arg in args])

        available_presets = preset_file.load(password)
        settings = common.options2settings(options)
        preset = presets.Preset(settings, **user_data)
        available_presets[options.preset_name] = preset
        preset_file.save(available_presets, password)
    
    
